import { Store } from "vuex"
const VUEX_STORAGE_KEY=import.meta.env.VITE_VUEX_KEY
export default function(storage:Storage){
  return (store:Store<any>) =>{
    const storeStr=storage.getItem(VUEX_STORAGE_KEY)
    if(storeStr){
      const storeData=JSON.parse(storeStr)
      store.replaceState(storeData)
    }
    window.addEventListener("unload", (e) =>{
      storage.setItem(VUEX_STORAGE_KEY,JSON.stringify(store.state))
    })
  }
}